* ==============================================================================
*	Title:	'They Take Our Houses': Benefit Competition and the Erosion of Support for Immigrants’ Social Rights
*	Author:	Gerda Hooijer
*	Date:	February 29, 2020
* 	Replication do file for: Main analysis
* ==============================================================================

version 16

set more off

// set directory

/*
*** Required datasets:
NL_dispersal.dta
nlcoord.dta
municipality_nl.dta
liss_L1L2.dta (restricted access)

*** Required Stata package:
spmap

*/


* Figure 1.
* National targets and dispersals of new refugees (2007-2016)

use "NL_dispersal", clear 

line targets refugees refugees_reg year, lpattern(solid longdash shortdash) lwidth(medthick medthick medthick) scheme(s1mono) legend(label(1 "National targets") label(2 "Dispersals") label(3 "Dispersals incl. regularization") col(1) region(lwidth(none))) ytitle("Dispersed refugees (x 10,000)") xtitle(" ") xlabel(2008(2)2016) yscale(titlegap(*+5)) plotregion(style(none)) 

graph export "figure_1.pdf", replace


* Figure 2. 
* Proportion of support for immigrants’ social rights (2007-2016)
* Mean support across waves
use "liss_L1L2", clear

keep if sample==1

save temp, replace // create a temporary dataset

statsby _b _se e(df_r), by(year) : regress include2 

rename _b_cons mean
rename _se_cons se
rename  _eq2_stat_1 df

gen lb = mean - invttail(df,0.025)*se
gen ub = mean + invttail(df,0.025)*se

tsset year
tsline mean lb ub

graph twoway line mean ub lb year, lpattern(solid dash dash) lwidth(medthick medium medium) scheme(s1mono) legend(order(1 2) label(1 "Mean support for immigrants' social rights") label(2 "95% Confidence interval") label(3 " ") col(1) region(lwidth(none))) ytitle("Pr(Support)", size(medsmall)) xtitle(" ") xlabel(2008(2)2016) ylabel(0.2(0.2)0.8) yscale(titlegap(*+5)) xscale(titlegap(*+5)) plotregion(style(none)) 

graph export "figure_2.pdf", replace

erase "temp.dta"


* Table 1. 
* Changes in support for immigrants’ social rights compared to the previous year
use "liss_L1L2", clear

tab d_include2 if sample==1


* Figure 3. 
* Share of vacant social housing allocated to new refugees across 388 municipalities 
use "municipality", clear 

// Panel A: 2009
spmap rfg_sh if year==2009 using "nlcoord.dta", id(id) fcolor(OrRd) clmethod(custom) clbreaks(0 5 10 15 25) legstyle(2) legend(size(medium) label(1 "No data") label(2 "0-5%") label(3 "5-10%") label(4 "10-15%") label(5 ">15%") position(4)) title(2009)

graph export "figure_3a.pdf", replace

// Panel B: 2015
spmap rfg_sh if year==2015 using "nlcoord.dta", id(id) fcolor(OrRd) clmethod(custom) clbreaks(0 5 10 15 25) legstyle(2) legend(size(medium) label(1 "No data") label(2 "0-5%") label(3 "5-10%") label(4 "10-15%") label(5 ">15%") position(4)) title(2015)

graph export "figure_3b.pdf", replace

// to display these figures in greyscale, replace fcolor(OrRd) with fcolor(Greys2)

* Figure 4. Distribution of changes in social housing allocations in the sample
use "liss_L1L2", clear

// Calculate the change in the share of social housing allocated to refugees compared to the previous period. Since the panel is unbalanced, a respondent's previous period can be more than the previous wave.
xtset nomem_encr year 
gen d_rfg_sh = rfg_sh - L.rfg_sh
replace d_rfg_sh = rfg_sh - L2.rfg_sh if d_rfg_sh==.
replace d_rfg_sh = rfg_sh - L3.rfg_sh if d_rfg_sh==.
replace d_rfg_sh = rfg_sh - L4.rfg_sh if d_rfg_sh==.
replace d_rfg_sh = rfg_sh - L5.rfg_sh if d_rfg_sh==.

histogram d_rfg_sh if sample==1, percent normal normop(lwidth(thin) lpattern(dash)) ytitle("Respondent-years (%)") ysca(titlegap(*+5)) xsca(titlegap(*+5)) xtitle("Change in social housing allocations (percentage points)")xticks(-20(5)20) scheme(s1mono) plotregion(style(none))

graph export "figure_4.pdf", replace


* Table 2. 
* Social housing allocations and support for immigrants’ social rights
use "liss_L1L2", clear

// Model 1
xtlogit include2 c.income_cpi3##c.rfg_sh i.year if sample==1, fe or

// Model 2
xtlogit include2 c.income_cpi3##c.rfg_sh i.year if sample==1 & sec_target==0, fe or

// Model 3
xtlogit include2 c.income_cpi3##c.rfg_sh i.year if sample==1 & sec_target==1, fe or

// Model 4
xtlogit include2 c.income_cpi3##c.rfg_sh age degree hhsize unemployed fb_pct asc sh_pct leduc_pct i.year if sample==1 & sec_target==1, fe or

// Model 5
xtlogit include2 c.income_cpi3##c.rfg_sh age degree hhsize unemployed fb_pct asc sh_pct leduc_pct decline i.year if sample==1 & sec_target==1, fe or

// Model 6
xtlogit include2 c.income_cpi3##c.rfg_sh age degree hhsize unemployed fb_pct asc sh_pct leduc_pct stu i.year if sample==1 & sec_target==1, fe or


* Table 3. 
* Social housing allocations and support for immigrants’ social rights by housing market tightness
use "liss_L1L2", clear

// Model 7
xtlogit include2 c.income_cpi3##c.rfg_sh age degree hhsize unemployed fb_pct asc sh_pct leduc_pct i.year if sample==1 & sec_target==1 & decline==1, fe or

// Model 8
xtlogit include2 c.income_cpi3##c.rfg_sh age degree hhsize unemployed fb_pct asc sh_pct leduc_pct i.year if sample==1 & sec_target==1 & decline==0, fe or

// Model 9
xtlogit include2 c.income_cpi3##c.rfg_sh age degree hhsize unemployed fb_pct asc sh_pct leduc_pct i.year if sample==1 & sec_target==1 & low_stu==1, fe or

// Model 10
xtlogit include2 c.income_cpi3##c.rfg_sh age degree hhsize unemployed fb_pct asc sh_pct leduc_pct i.year if sample==1 & sec_target==1 & low_stu==0, fe or


* Figure 5. 
* Social housing competition, income, and support for immigrants’ social rights
use "liss_L1L2", clear

// Create respondent-means for all time-varying variables for this group 
egen income_m = mean(income_cpi3) if sample==1 & sec_target==1 & decline==0, by(nomem_encr)
egen rfg_sh_m = mean(rfg_sh) if sample==1 & sec_target==1 & decline==0, by(nomem_encr)
egen age_m = mean(age) if sample==1 & sec_target==1 & decline==0, by(nomem_encr)
egen degree_m = mean(degree) if sample==1 & sec_target==1 & decline==0, by(nomem_encr)
egen hhsize_m = mean(hhsize) if sample==1 & sec_target==1 & decline==0, by(nomem_encr)
egen unemployed_m = mean(unemployed) if sample==1 & sec_target==1 & decline==0, by(nomem_encr)
egen fb_m = mean(fb_pct) if sample==1 & sec_target==1 & decline==0, by(nomem_encr)
egen asc_m = mean(asc) if sample==1 & sec_target==1 & decline==0, by(nomem_encr)
egen sh_m = mean(sh_pct) if sample==1 & sec_target==1 & decline==0, by(nomem_encr)
egen leduc_m = mean(leduc_pct) if sample==1 & sec_target==1 & decline==0, by(nomem_encr)

// Correlated Random Effects Probit Model
xtprobit include2 c.income_cpi3##c.rfg_sh age degree hhsize unemployed fb_pct asc sh_pct leduc_pct i.year income_m rfg_sh_m age_m degree_m hhsize_m unemployed_m fb_m asc_m sh_m leduc_m if sample==1 & sec_target==1 & decline==0, re vce(cluster nomem_encr) 

// Calculate average marginal effects 
margins, dydx(rfg_sh) at(income_cpi3=(1.8(0.5)7.3)) asbalanced
matrix b=r(b)'
matrix list b
matrix at=r(at)
matrix at=at[1...,"income_cpi3"]
matrix list at
matrix v = r(V)
matrix list v
matrix se=vecdiag(cholesky(diag(vecdiag(v))))'
matrix list se
matrix d=at,b,se
matrix list d
svmat d, names(d)
generate ul = d2 + 1.96*d3
generate ll = d2 - 1.96*d3

// Plot 
graph twoway line d2 ul ll d1, yline(0, lcolor(gs1)) lpattern(solid dash dash) lwidth(medium medthin medthin) lcolor(gs1 gs1 gs1) c(l) || kdensity income_cpi3 if sample==1 & income_cpi3>=1.8 & income_cpi3<=7.3, lpattern(dot) lcolor(gs5) xaxis(2) c(l) xscale(axis(2) range(1.8(0.5)7.3) off) yaxis(2) c(l) yscale(axis(2) range(0(0.1)1) off) legend(on order(1 2 4) col(1) label(1 "Effect of competition on support for immigrants' social rights") label(2 "95% Confidence interval") label(4 "Density plot of income") region(lwidth(none)) size(small)) xtitle("Income (x €1,000)") ytitle("Marginal effect of competition", size(medsmall)) title("") plotregion(style(none)) yscale(titlegap(*+10)) xscale(titlegap(*+10)) scheme(s1mono)

graph export "figure_5.pdf", replace


* Table 4. 
* Social housing allocations and support for the populist right by housing market tightness
use "liss_L1L2", clear

// Model 11
xtreg pvv_symp c.income_cpi3##c.rfg_sh age degree hhsize unemployed fb_pct asc sh_pct leduc_pct i.year if sample==1 & sec_target==1 & decline==1, fe robust

// Model 12
xtreg pvv_symp c.income_cpi3##c.rfg_sh age degree hhsize unemployed fb_pct asc sh_pct leduc_pct i.year if sample==1 & sec_target==1 & decline==0, fe robust

// Model 13
xtreg pvv_symp c.income_cpi3##c.rfg_sh age degree hhsize unemployed fb_pct asc sh_pct leduc_pct i.year if sample==1 & sec_target==1 & low_stu==1 , fe robust

// Model 14
xtreg pvv_symp c.income_cpi3##c.rfg_sh age degree hhsize unemployed fb_pct asc sh_pct leduc_pct i.year if sample==1 & sec_target==1 & low_stu==0, fe robust